package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.cqupt.cxcy.dao.IndexDao;
import cn.edu.cqupt.cxcy.dto.IndexImpl;
import cn.edu.cqupt.cxcy.model.Noticetype;


/**
 * 主页-【场地预约】
 * @author Dancer-mno
 * @date 2015年10月17日
 */
@SuppressWarnings("serial")
public class IndexNavCdyy_Receipt extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String pjax_back = "$(function(){$(\"a.pjax[href='index_cdyy_Receipt']\").trigger('click');});";
		if(req.getHeader("x-pjax") == null || req.getHeader("x-pjax").equals("null")) {
			req.setAttribute("pjax_back", pjax_back);
			List<Noticetype> nt = new IndexImpl().noticeTypes();
			req.setAttribute("nt", nt);
			req.getRequestDispatcher("html/index.jsp").forward(req, resp);
			return;
		}  else {
			HttpSession session = req.getSession();
			@SuppressWarnings("unchecked")
			List<Object> user= (List<Object>) session.getAttribute( "user");
			List<Object> lists = null;
			int sum = 1;
			if(user != null) {
				IndexDao index = new IndexImpl();
				lists = index.listCdyy((String)user.get(4), 1, IndexDao.PAGING_CDYY);
				sum  = (int)Math.ceil( (double)index.countCdyy( (String)user.get(4)) / IndexDao.PAGING_CDYY);
			}
			req.setAttribute("lists", lists);
			req.setAttribute("sum", sum);
			req.getRequestDispatcher("html/cdyy_hz.jsp").forward(req, resp);
		}
	}


}
